package day03;

import java.util.Scanner;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/9
 */
public class GoldbachConjecture {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.print("请输入一个不小于6的偶数（输入0退出）：");
            int a = scanner.nextInt();

            // 检查是否要退出
            if (a == 0) {
                System.out.println("程序已退出。");
                break;
            }

            // 验证输入是否有效
            if (a < 6 || a % 2 != 0) {
                System.out.println("输入无效，请输入不小于6的偶数！");
                continue;
            }

            // 寻找素数对
            boolean found = false;
            for (int x = 3; x <= a / 2; x += 2) {  // 只检查奇数
                // 检查x是否为素数
                boolean xIsPrime = true;
                if (x <= 1) {
                    xIsPrime = false;
                } else if (x == 2) {
                    xIsPrime = true;
                } else if (x % 2 == 0) {
                    xIsPrime = false;
                } else {
                    for (int i = 3; i * i <= x; i += 2) {
                        if (x % i == 0) {
                            xIsPrime = false;
                            break;
                        }
                    }
                }

                // 检查y是否为素数
                if (xIsPrime) {
                    int y = a - x;
                    boolean yIsPrime = true;
                    if (y <= 1) {
                        yIsPrime = false;
                    } else if (y == 2) {
                        yIsPrime = true;
                    } else if (y % 2 == 0) {
                        yIsPrime = false;
                    } else {
                        for (int i = 3; i * i <= y; i += 2) {
                            if (y % i == 0) {
                                yIsPrime = false;
                                break;
                            }
                        }
                    }

                    // 如果x和y都是素数，输出结果
                    if (yIsPrime) {
                        System.out.println(a + " = " + x + " + " + y);
                        found = true;
                    }
                }
            }

            if (!found) {
                System.out.println("未找到符合条件的素数对！");
            }
        }
    }
}
